class UnexpectedErr {
  /**
   * 函数入参判空
   * @param {String} fnName        标识错误位置
   * @param {String} para          为空的参数描述
   */
  static fnArgumentsEmptyErr(fnName, para) {
    fnName = !fnName ? 'SomeFunction' : fnName
    para = !para ? '' : para
    throw new Error(`${fnName} without parameter ${para}. Please confirm parameter is not empty.`)
  }

  /**
   * 指定类型判空
   * @param {dynamic} arg 
   * @param {String} type 
   */
  static fixedTypeEmptyErr(arg, type = 'string') {
    // 需要处理为0的情况
    if (arg === 0) {
      UnexpectedErr.errTip((typeof arg).toString() !== type, `Need a ${type}, But get a number`)
    } else {
      UnexpectedErr.errTip(!arg, `Argument is ${arg}, Please confirm parameter is not empty`)
    }
    
    UnexpectedErr.errTip((typeof arg).toString() !== type, `Need a ${type}, But get a ${typeof arg}`)
    return arg
  }

  static errTip(codition, tip = 'Uncatch error occurred') {
    if (codition) throw new Error(tip)
  }
}

export default UnexpectedErr
